package org.zero.onlinesubject.utils;

import com.mysql.cj.util.StringUtils;

import java.util.regex.Pattern;

public class ValidatorUtil {
    private static final Pattern Phone_Pattern = Pattern.compile("^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\\d{8}$");
//    private static final Pattern Name_Pattern = Pattern.compile("^[0-9A-Za-z_-\u4e00-\u9fa5]{2,}$");
    private static final Pattern Name_Pattern = Pattern.compile("\\w{2,}");
    private static final Pattern Email_Pattern = Pattern.compile("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$");
    private static final Pattern Captcha_Pattern = Pattern.compile("^[a-zA-Z\\d]{6}$");

    public static boolean isPhone(String phone){
        if(StringUtils.isNullOrEmpty(phone)){
            return false;
        }
        return Phone_Pattern.matcher(phone).matches();
    }

    public static boolean isName(String name){
        if(StringUtils.isNullOrEmpty(name)){
            return false;
        }
        return Name_Pattern.matcher(name).matches();
    }

    public static boolean isEmail(String email){
        if(StringUtils.isNullOrEmpty(email)){
            return false;
        }
        return Email_Pattern.matcher(email).matches();
    }

    public static boolean isCaptcha(String captcha){
        if(StringUtils.isNullOrEmpty(captcha)){
            return false;
        }
        return Captcha_Pattern.matcher(captcha).matches();
    }

    public static void main(String[] args) {

    }
}
